package com.fenghuajueli.module_user.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.WindowManager;

import androidx.annotation.DrawableRes;

import com.blankj.utilcode.util.SizeUtils;
import com.fenghuajueli.module_user.R;
import com.fenghuajueli.module_user.databinding.DialogUserTipBinding;

public class UserTipDialog extends Dialog {


    private DialogUserTipBinding binding;
    private int tipIcon = 0;
    private String tipStr = "";

    public UserTipDialog(Context context) {
        super(context, com.fenghuajueli.libbasecoreui.R.style.StyleBaseDialog);
    }

    public UserTipDialog(Context context, @DrawableRes int tipIcon, String tipStr) {
        super(context, com.fenghuajueli.libbasecoreui.R.style.StyleBaseDialog);
        this.tipIcon = tipIcon;
        this.tipStr = tipStr;
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DialogUserTipBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width = SizeUtils.dp2px(110);
        layoutParams.height = SizeUtils.dp2px(110);
        getWindow().setAttributes(layoutParams);

        if (!tipStr.isEmpty()) {
            binding.tvTipStr.setText(tipStr);
        }

        if (tipIcon != 0) {
            binding.ivIcon.setImageResource(tipIcon);
        }
    }


    @Override
    public void show() {
        super.show();
        binding.tvTipStr.postDelayed(this::dismiss, 1500);
    }

    public static UserTipDialog show(Context context, @DrawableRes int tipIcon, String tipStr) {
        UserTipDialog userTipDialog = new UserTipDialog(context, tipIcon, tipStr);
        userTipDialog.show();
        return userTipDialog;
    }
}
